% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/RcppExports.R
\name{by_year}
\alias{by_year}
\title{Apply a function to a Data Frame split by year}
\usage{
by_year(x, dates, fn)
}
\arguments{
\item{x}{\code{DataFrame}}

\item{dates}{\code{DateVector} that will be grouped by year and
used to split \code{x}.}

\item{fn}{\code{Function} applied to each group after splitting
\code{x}. The function signature is the corresponding
sub-\code{DataFrame} and sub-\code{DateVector}.}
}
\description{
\code{by_year} splits a \code{DataFrame} by a \code{DateVector}
grouped by year and applies the supplied function to each element in
the resulting \code{list}.
}
\details{
When splitting \code{x}, \code{by_year} will balance
         the groups. This means that if there's an intra-year
         change not on January 1st, the last observation in the
         previous year will be copied to January 1st. The
         rationale is that each group should contain the year's
         full codings --- especially since we usually apply the
         day-weighted mean function (\code{\link{day_mean}}) to
         each group.
}
\examples{
df <- data.frame(x = 1:3)
dates <- as.Date(c("1900-01-01", "1901-02-01", "1901-11-01"))
by_year(df, dates, list)

}
